Welcome Login
Blog Photos Links

RSS Feed

ServiceNow Workflow Join Activity

October 7, 2013, 6:30 pm - James Farrer

A few weeks ago I came across an issue involving a Workflow Join Activity and some confusion around what it does and how it works. There is a little bit of documentation on the wiki but it still left some questions unanswered.

The purpose of the Join Activity is to combine two or more paths of execution after they have branched out. This serves the purpose of ensuring that subsequent activities will not get run multiple times with unexpected results.

A Join activity will always wait for all active paths of execution to reach it before proceeding.

The difference between the Complete and Incomplete outputs comes down to whether or not all possible paths of execution have completed. For example, if there is a split to have two simultaneous tasks on parallel paths then after both tasks have completed the Join will finish with Complete.

To contrast that, when there is an if statement, only one path will ever actually get executed so the Join will always exit as Incomplete.

Hopefully that clarifies things a bit for you; it certainly helped me to review how it worked.

Remove invalid characters from a field in ServiceNow

July 1, 2013, 10:34 am - James Farrer

Over the weekend I helped with an issue that came up involving form validation in ServiceNow. I've seen this a few times so I thought I'd throw out a reminder to myself and others about it. The goal was to remove invalid characters from a field leaving only numbers. At first this seems pretty simple, just do a regex and set the new value.

It's really not much more complicated than that, but there is one more very important step to take. Since the code is running in an onChange client script if you just set the new value then it will cause the onChange to run again. This onChange will run even if the value hasn't changed.

The trick is to perform a simple check in the function for whether the updated string is different than the original and only updating the value if it has changed. In general this is a good practice that often gets overlooked.

Leaving it out will result in StackOverflow errors from an infinite loop of onChange calls.

Here's the client script code, just replace "your_variable_name" with your own and you should be on your way:

function onChange(control, oldValue, newValue, isLoading) {
    
    // remove invalid characters from field
    var clean_str = newValue.replace(/[^d]/g,'');
    
    if(newValue != clean_str){
        g_form.setValue('your_variable_name', clean_str);
    }
    
}

How do you deploy code?

June 20, 2013, 10:48 am - James Farrer

I ran across an interesting article about how Netflix deploys code. Here's the link to it:

http://www.infoq.com/news/2013/06/netflix

It had several intersting things to consider. I might have to look into the DevOps stuff they mentioned. I've heard a bit about it, but I might look into it a little deeper.

I also thought the Chaos and Latency Monkeys were an interesting concept. Intentionally make things fail often enough that you are forced to accomodate for it, then when a real failure happens it's not a big deal.

Regex is SLOW!

April 8, 2013, 6:09 pm - James Farrer

I had an interesting experience today with a script in ServiceNow (server side javascript) that was replacing variables in a large string (~28000 characters). We were using a regex to find and replace all occurances of 10-15 variables in the string. When I first wrote the code to do the replacing the string we were using was only a few lines and even as it started to grow we didn't notice any speed issues but then we added a large chunk of text and wow! We went from a second or two up to about 30 seconds of processing just to do this replacing.

I was honestly a bit surprised at how long it took to process. I tried a few things to see what I could do to speed it up and was almost to the point of setting up a painful caching process when I decided to try my hand at manually writing the replacement script. Boy am I glad I did!

In the string the variables I am replacing are nicely bracketed in the format of "[[var_name]]". So I took the string and used the split function on it with "[[" as the delimiter. Then I took each row (minus the first that wouldn't have a variable in it) and split it again on the ending portion of "]]". Then I used a really simple associative array lookup with the first part of the second array and rebuilt the string with the results.

At first I couldn't believe the results, but after testing and verifying, I found that it was taking longer to log results than it was taking to actually do the processing. That's an improvement from 30,000+ ms down to about 10 ms. 

Now I thought Regex might not be incredibly fast, but this truly amazed me. Not only is the syntax a bit cryptic, but it's slow. Next time I'll definitely think twice before using a regex.


What's New

There are currently no new items, please check back later.

Archives
2021 (2)
  September (1)
  May (1)
2019 (1)
  August (1)
2018 (3)
  August (1)
  April (1)
  January (1)
2017 (1)
  January (1)
2016 (4)
  December (1)
  November (1)
  May (1)
  January (1)
2015 (1)
  December (1)
2014 (2)
  August (1)
  February (1)
2013 (4)
  October (1)
  July (1)
  June (1)
  April (1)
2012 (11)
  December (2)
  October (3)
  September (1)
  May (1)
  April (1)
  February (2)
  January (1)
2011 (14)
  December (1)
  November (1)
  September (2)
  July (2)
  June (1)
  May (1)
  April (2)
  March (3)
  January (1)
2009 (2)
  October (1)
  June (1)
2008 (1)
  September (1)